package xyz.zhouzhaodong.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 交换机
 * @author zhouzhaodong
 */
@Configuration
public class SenderConfig {

    /**
     * ----- 交换机 -----
     * 参数意义:
     *   name: 名称
     *   durable: 持久化
     *   autoDelete: 自动删除
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("topicExchange", true, false);
    }

    /**
     * ----- 队列 -----
     */
    @Bean
    public Queue queueOne() {
        return new Queue("queueOne", true);
    }

    @Bean
    public Queue queueTwo() {
        return new Queue("queueTwo", true);
    }

    @Bean
    public Queue queueThree() {
        return new Queue("queueThree", true);
    }

    /**
     * ----- 绑定 -----
     * routingKey就是路由规则，消息对应的队列，用来区分不同的消息队列
     */
    @Bean
    public Binding bindingFanoutOne() {
        return BindingBuilder.bind(queueOne()).to(topicExchange()).with("topic_one");
    }

    @Bean
    public Binding bindingFanoutTwo() {
        return BindingBuilder.bind(queueTwo()).to(topicExchange()).with("topic_two");
    }

    @Bean
    public Binding bindingFanoutThree() {
        return BindingBuilder.bind(queueThree()).to(topicExchange()).with("topic_one");
    }

}
